package com.sky.service.impl;

import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.mapper.DishFlavorMapper;
import com.sky.mapper.UserDishMapper;
import com.sky.service.UserDishService;
import com.sky.vo.DishVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: Sabrina
 * @Date:2025/06/10/17:19
 * @Description:
 */
@Service
public class UserDishServiceImpl implements UserDishService {
    @Autowired
    private UserDishMapper userDishMapper;
    @Autowired
    private DishFlavorMapper dishFlavorMapper;


    /**
     * 根据分类id查询菜品,启售才能查出来
     * @param dish
     * @return
     */
    @Transactional
    @Override
    public List<DishVO> getDisheByCategoryId(Dish dish) {
        List<DishVO> list= userDishMapper.getDisheByCategoryId(dish.getCategoryId());
        for (DishVO vo : list) {
            Long id = vo.getId();
            List<DishFlavor> flavors = dishFlavorMapper.getByDishId(id);
            vo.setFlavors(flavors);
        }
        return list;
    }

}
